﻿using EasyNet.Componets.Core.Emails;
using EasyNet.Componets.Core.Inject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyNet.Componets.Core.Utils
{
    public static class EmailUtil
    {
        private static IEmail _instance;

        public static IEmail Instance
        {
            get
            {
                if (_instance != null)
                {
                    return _instance;
                }
                try
                {
                    _instance = IoC.Resolve<IEmail>();
                }
                catch
                {
                    _instance = new EasyNetQQEmail();
                }
              
                return _instance;
            }
        }


        /// <summary>
        /// 设置实例
        /// </summary>
        /// <param name="instance"></param>
        public static void SetInstance(IEmail instance)
        {
            _instance = instance;
        }

        public static void Send(EmailModel email)
        {
            Instance.Send(email);
        }
    }
}
